package com.spzx.product.controller;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.product.api.domain.Product;
import com.spzx.product.api.domain.ProductDetails;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.api.domain.vo.SkuPriceVo;
import com.spzx.product.api.domain.vo.SkuStockVo;
import com.spzx.product.service.ProductService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 商品sku 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2024-10-26
 */
@RestController
@RequestMapping("/productSku")
public class ProductSkuController extends BaseController {

    @Autowired
    private ProductService productService;


    @InnerAuth
    @Operation(summary = "供微服务内部远程调用获取商品sku的接口")
    @GetMapping("/getProductSkuById/{skuId}")
    public R<ProductSku> getProductSkuById(@PathVariable("skuId") Long skuId){
        //调用自带的根据Id查询方法
        ProductSku byId = productService.getProductSkuById(skuId);
        return R.ok(byId);
    }

    @InnerAuth
    @Operation(summary = "供微服务内部远程调用获取商品信息的接口")
    @GetMapping("/getPrductById/{id}")
    public R<Product> getProductById(@PathVariable("id") Long id){
        //调用自带的根据ID查询方法
        Product byId = productService.getProductInfoById(id);
        return R.ok(byId);
    }

    @InnerAuth
    @Operation(summary = "供微服务内部远程调用获取商品Sku价格的接口")
    @GetMapping("/getSkuPriceVoBySkuId/{skuId}")
    public R<SkuPriceVo> getSkuPriceVoBySkuId(@PathVariable("skuId") Long skuId){
        //调用自定义根据SkuId获取SkuPriceVo信息
        SkuPriceVo skuPriceVo = productService.getSkuPriceVoBySkuId(skuId);
        return R.ok(skuPriceVo);
    }

    @InnerAuth
    @Operation(summary = "获取商品详细信息")
    @GetMapping(value = "/getProductDetails/{id}")
    public R<ProductDetails> getProductDetails(@PathVariable("id") Long id)
    {
        return R.ok(productService.getProductDetails(id));
    }

    @InnerAuth
    @Operation(summary = "获取商品sku规则详细信息")
    @GetMapping(value = "/getSkuSpecValue/{id}")
    public R<Map<String, Long>> getSkuSpecValue(@PathVariable("id") Long id)
    {
        return R.ok(productService.getSkuSpecValue(id));
    }

    @InnerAuth
    @Operation(summary = "获取商品sku库存信息")
    @GetMapping(value = "/getSkuStock/{skuId}")
    public R<SkuStockVo> getSkuStock(@PathVariable("skuId") Long skuId)
    {
        return R.ok(productService.getSkuStock(skuId));
    }

}
